package cn.cvs.service.impl;

import cn.cvs.dao.SysUserMapper;
import cn.cvs.pojo.SysUser;
import cn.cvs.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("sysUserServiceImpl")
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    @Qualifier("sysUserMapper")
    private SysUserMapper sysUserMapper;
    @Override
    public SysUser login(String account, String password) {
        SysUser sysUser = sysUserMapper.findByAccount(account);
        if (sysUser==null){
            return null;
        }
        if (!password.equals(sysUser.getPassword()))
            return null;
        return sysUser;
    }

    @Override
    public List<SysUser> list(Integer pageIndex, Integer pageSize, String realName, Integer roleId) {
        List<SysUser> list = sysUserMapper.userList(pageIndex, pageSize,realName,roleId);
        return list;
    }

    @Override
    public int add(SysUser sysUser) {
        int result =sysUserMapper.add(sysUser);
        return result;
    }

    @Override
    public int count(String realName) {
        int result =sysUserMapper.count(realName);
        return result;
    }

    @Override
    public int delete(Integer id) {
        int result = sysUserMapper.delete(id);
        return result;
    }

    @Override
    public SysUser getUserById(String id) {
        return sysUserMapper.getUserById(id);
    }

    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    @Override
    public SysUser getAccountExist(String account) {
        return sysUserMapper.findByAccount(account);
    }


}
